<?php
namespace Core\Extensions\Modules\WebDeveloper\Libs\Clipboard;

class Html {

	private static $index = NULL;
	private static $isInteger = TRUE;
	private static $arrayHtmlClipboard = array();

	final public function init() {

		reset(self::$arrayHtmlClipboard);
	}

	final public static function getIndex() {

		if(is_array(self::$arrayHtmlClipboard) && count(self::$arrayHtmlClipboard) > 0) {

			self::$index = key(self::$arrayHtmlClipboard);

			if(is_int(self::$index)) {

				self::$isInteger = TRUE;
			}

			else {

				self::$isInteger = FALSE;
			}

			return self::$index;
		}

		return self::$index = NULL;
	}

	final public static function setIndex($index = NULL) {

		if(!empty($index) && is_array(self::$arrayHtmlClipboard) && count(self::$arrayHtmlClipboard) > 0) {

			if(self::$isInteger) {

				self::$index = (int)self::$index;
			}

			else {

				self::$index = (string)self::$index;
			}

			$key = key(self::$arrayHtmlClipboard);
			$next = FALSE;

			while($key !== self::$index || !$next) {

				$next = next(self::$arrayHtmlClipboard);

				if($next) {

					$key = key(self::$arrayHtmlClipboard);
				}
			}

			if($key === self::$index) {

				unset($next, $key);
				return TRUE;
			}			

			unset($next, $key);
		}

		return FALSE;
	}

	final public static function add($inputDOMElementPath = NULL, $inputFilePath = NULL, $uuid = NULL, $outputFilePath = NULL, $getNext = TRUE) {

		if(!empty($inputDOMElementPath) && !empty($inputFilePath) && !empty($uuid) && !empty($outputFilePath)) {

			self::$arrayHtmlClipboard[] = array('inputDOMElementPath' => $inputDOMElementPath, 'inputFilePath' => &$inputFilePath, 'uuid' => $uuid, 'outputFilePath' => $outputFilePath);

			if($getNext) {

				self::getNext();
			}

			return TRUE;
		}

		return FALSE;
	}

	final public static function remove($getPrevious = TRUE) {

		if(is_array(self::$arrayHtmlClipboard) && count(self::$arrayHtmlClipboard) > 0) {

			unset(self::$arrayHtmlClipboard[key(self::$arrayHtmlClipboard)]);

			if($getPrevious) {

				self::getPrevious();
			}

			return TRUE;
		}

		return FALSE;
	}

	final public static function removeAll() {

		self::$arrayHtmlClipboard = array();
	}

	final public static function getCurrent($key = NULL, $getPrevious = TRUE) {

		if(is_array(self::$arrayHtmlClipboard) && count(self::$arrayHtmlClipboard) > 0) {

			if($key === NULL) {

				$value = current(self::$arrayHtmlClipboard);

				if($getPrevious) {

					self::getPrevious();
				}

				return $value;
			}

			elseif(array_key_exists($key, &self::$arrayHtmlClipboard)) {

				return self::$arrayHtmlClipboard[$key];
			}
		}

		return FALSE;
	}

	final public static function getAndRemove($getPrevious = TRUE) {

		if(is_array(self::$arrayHtmlClipboard) && count(self::$arrayHtmlClipboard) > 0) {

			$value = current(self::$arrayHtmlClipboard);
			unset(self::$arrayHtmlClipboard[key(self::$arrayHtmlClipboard)]);

			if($getPrevious) {

				self::getPrevious();
			}

			return $value;
		}

		return FALSE;
	}

	final public static function getPrevious() {

		if(is_array(self::$arrayHtmlClipboard) && prev(self::$arrayHtmlClipboard)) {

			return TRUE;
		}

		return FALSE;
	}

	final public static function getNext() {

		if(is_array(self::$arrayHtmlClipboard) && next(self::$arrayHtmlClipboard)) {

			return TRUE;
		}

		return FALSE;
	}

	final public static function getArrayHtmlClipboard() {

		return self::$arrayHtmlClipboard;
	}

	final public static function persist($type = 0) {

		
	}
}
?>